/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-06-20 15:36:19
 * @LastEditors: dark-snow 1306808708@qq.com
 * @LastEditTime: 2023-07-06 09:27:24
 * @FilePath: \Wifi_Socket_Server_230620\main\softap_example_main.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*  WiFi softAP Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_mac.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"

#include "esp_netif.h"

#include "lwip/err.h"
#include "lwip/sys.h"
// #include "lwip/sockets.h"
#include "sys/socket.h"

#include "user_wifi.h"
#include "user_socket.h"
// #include "user_dict.h"
#include "user_uart.h"
#include "user_spi.h"

static const char *TAG = "wifi softAP";

#define WIFI_AP_IP "192.168.10.103"

void app_main(void)
{
    // Initialize NVS
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    uart_init(115200);
    uart_tx_SendData("hello world");
    xTaskCreate(uart_rx_task, "uart task", 4096, NULL, 3, NULL);

    ESP_LOGI(TAG, "ESP_WIFI_MODE_AP");

    xTaskCreate(wifi_app_task, "wifi app task", 4096 * 2, NULL, 5, NULL);

    // user_wifi_ap_start(WIFI_AP_IP);

    while (1)
    {
        // uart_tx_SendData("hello world");
        vTaskDelay(2000 / portTICK_PERIOD_MS);
    }
    // xTaskCreate(tcp_client_task, "tcp_client", 4096, NULL, 5, NULL);
}
